#===============================================================================
# Under development
#===============================================================================

# Enthought library imports
from enthought.chaco.api import HPlotContainer, VPlotContainer, OverlayPlotContainer, \
                                Plot, PlotAxis

from enthought.traits.api import Any, Array, Callable, CFloat, CInt, Enum, Event, Float, HasTraits, \
                             Int, Range, Button, Instance, Str, File, Trait, on_trait_change, DelegatesTo
from enthought.traits.ui.api import Group, Handler, HGroup, Item, View, StatusItem, \
                                    HSplit
from enthought.traits.ui.menu import Action, CloseAction, Menu, \
                                     MenuBar, NoButtons, Separator, ToolBar
from enthought.enable.api import ComponentEditor


class GprViewer(HasTraits):
    # Container holding the control items
    ctrlcontainer = Instance(HPlotContainer)
    
    # Container holding the CMapImagePlot, colorbar .
    cmapcontainer = Instance(HPlotContainer)
    
    # Container holding the TraceLinePlot.
    tplotcontainer = Instance(HPlotContainer)
    
    menubar = Instance(MenuBar)
    
    controller = Instance(Handler)
    
    # Default View for object
    traits_view = View(HSplit(
                              Item('ctrlcontainer', editor=ComponentEditor(size=(140, 1.0)), 
                                   show_label=False, style='custom',
                                   ),
                              Item('cmapcontainer', editor=ComponentEditor(), 
                                   show_label=False, style='custom',
                                   ),
                              Item('tplotcontainer', editor=ComponentEditor(size=(200, 1.0)), 
                                   show_label=False, style='custom',
                                   ),
                              ),
                       title='GPR Viewer',
                       height=0.8, width=0.8,
                       resizable=True
                       )
    
    def __init__(self):
        
        self.trait_view("traits_view").menubar=self.create_menubar()
    
    
    def create_menubar(self):
            #------------------------------------------------------------------------------
        #  File Menu:
        #------------------------------------------------------------------------------
        new_action = Action(name="&New", accelerator="Ctrl+N", action="new_model",
            tooltip="New (Ctrl+N)", image=r"../src/resources/icons/filenew-32.png")
        open_action = Action(name="&Open", accelerator="Ctrl+O", action="open_file",
            tooltip="Open (Ctrl+O)", image=r"../src/resources/icons/fileopen-32.png")
        save_action = Action(name="&Save",# accelerator="Ctrl+S",
            action="save", tooltip="Save (Ctrl+S)", image=r"../src/resources/icons/filesave-32.png")
        save_as_action = Action(name="Save &As", accelerator="Ctrl+Shift+S",
            action="save_as", tooltip="Save As (Ctrl+Shift+S)",
            image=r"../src/resources/icons/filesaveas-32.png")
        # Action to revert all changes.
        revert_action = Action(name="Revert", action="_on_revert",
            defined_when="ui.history is not None", enabled_when="ui.history.can_undo")
        # Action to close the view window.
        close_action = Action(name="E&xit", accelerator="Alt+X", action="on_exit",
            tooltip="Exit (Alt+X)")
        
        file_menu = Menu(open_action,
                         save_action,
                         CloseAction,
                         name="File")
        
        #------------------------------------------------------------------------------
        #  Edit Menu:
        #------------------------------------------------------------------------------
        # Action to undo last change.
        undo_action = Action(name="Undo", action="_on_undo", accelerator="Ctrl+Z",
            defined_when="ui.history is not None", enabled_when="ui.history.can_undo",
        #    image=ImageResource("undo"),
            tooltip="Undo (Ctrl+Z)")
        # Action to redo last undo.
        redo_action = Action(name="Redo", action="_on_redo", accelerator="Ctrl+Y",
            defined_when="ui.history is not None", enabled_when="ui.history.can_redo",
        #    image=ImageResource("redo.png"),
            tooltip="Redo (Ctrl+Y)")
        # Action to edit plot options
        plot_action = Action(name="Edit Plot ...", action="edit_plot", accelerator="Ctrl+E",
                             tooltip="Edit plot options (Ctrl+E)",
                             image=r"../src/resources/icons/edit-32.png")
        
        options_action = Action(name="Prefere&nces", action="godot_options")
        
        edit_menu = Menu(undo_action,
                         redo_action,
                         plot_action,
                         name="Edit")
        
        #------------------------------------------------------------------------------
        #  View Menu:
        #------------------------------------------------------------------------------
        zoomtool_action = Action(name="Zoom", action="activate_zoomtool",
                                 image=r"../src/resources/icons/viewmag+-32.png")
        
        metadata_action = Action(name="Meta Data", action="show_metadata")
        
        trackplot_action = Action(name="Track Plot", action="show_trackplot")
        
        skindepth_show = False
        skindepth_action = Action(name="Skin Depth", accelerator="Ctrl+D",
                                  action="show_skindepth", tooltip="",
                                  style="toggle", checked=skindepth_show)
        
        view_menu = Menu(zoomtool_action, "_",
                         metadata_action,
                         trackplot_action,
                         skindepth_action,
                         name="View")
        
        #------------------------------------------------------------------------------
        #  Tool Menu:
        #------------------------------------------------------------------------------
        picktool_action = Action(name="Pick Tool", action="activate_picktool",
                                 accelerator="Ctrl+P",
                                 image=r"../src/resources/icons/lin_agt_wrench-32.png")
        traceselect_action = Action(name="Trace Select Tool", action="activate_traceselecttool")
        
        
        
        tool_menu = Menu(picktool_action,
                         traceselect_action,
                         name="Tools")
        
        # Make a tool bar with the most common methods
        toolbar = ToolBar(
                "|", CloseAction, open_action, "_",plot_action,
                show_tool_names=False#, show_divider=False
                )
        
        menubar=MenuBar(file_menu,
                        edit_menu,     
                        view_menu,  
                        tool_menu)
        
        return menubar
    
if __name__ == "__main__":
    gv = GprViewer()
    gv.configure_traits()